package com.tss.service.impl;

import com.tss.service.DeviceService;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 设备状态管理实现类
 */
public class DeviceServiceImpl implements DeviceService {
    private boolean keyboardStatus = true;
    private boolean displayStatus = true;
    private boolean printerStatus = true;
    private boolean cardReaderStatus = true;
    private boolean coinSlotStatus = true;
    private boolean billSlotStatus = true;

    @Override
    public boolean checkAllStatus() {
        // 模拟自检过程
        keyboardStatus = true;
        displayStatus = true;
        printerStatus = true;
        cardReaderStatus = true;
        coinSlotStatus = true;
        billSlotStatus = true;
        
        return isDeviceReady();
    }

    @Override
    public boolean isDeviceReady() {
        return keyboardStatus && displayStatus && printerStatus && 
               cardReaderStatus && coinSlotStatus && billSlotStatus;
    }

    @Override
    public boolean printTicket(String destinationName, String ticketType, String category, double price, int quantity) {
        if (!printerStatus) {
            return false;
        }
        
        // 模拟打印车票
        System.out.println("========== 车票信息 ==========");
        System.out.println("目的地: " + destinationName);
        System.out.println("票类型: " + ticketType);
        System.out.println("坐席类型: " + category);
        System.out.println("价格: ¥" + price);
        System.out.println("数量: " + quantity);
        System.out.println("日期: " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        System.out.println("==============================");
        
        return true;
    }
    
    // Getter和Setter方法
    public boolean isKeyboardStatus() {
        return keyboardStatus;
    }

    public void setKeyboardStatus(boolean keyboardStatus) {
        this.keyboardStatus = keyboardStatus;
    }

    public boolean isDisplayStatus() {
        return displayStatus;
    }

    public void setDisplayStatus(boolean displayStatus) {
        this.displayStatus = displayStatus;
    }

    public boolean isPrinterStatus() {
        return printerStatus;
    }

    public void setPrinterStatus(boolean printerStatus) {
        this.printerStatus = printerStatus;
    }

    public boolean isCardReaderStatus() {
        return cardReaderStatus;
    }

    public void setCardReaderStatus(boolean cardReaderStatus) {
        this.cardReaderStatus = cardReaderStatus;
    }

    public boolean isCoinSlotStatus() {
        return coinSlotStatus;
    }

    public void setCoinSlotStatus(boolean coinSlotStatus) {
        this.coinSlotStatus = coinSlotStatus;
    }

    public boolean isBillSlotStatus() {
        return billSlotStatus;
    }

    public void setBillSlotStatus(boolean billSlotStatus) {
        this.billSlotStatus = billSlotStatus;
    }
} 